/**
 * 
 */
package org.ztest.spring.jdbc;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import com.jolbox.bonecp.BoneCPDataSource;

/**
 * @author lhl
 *
 *         2016年2月23日 下午2:59:51
 */
@Configuration
@ComponentScan("org.ztest.spring.jdbc")
public class JDBCDI
{
    @Bean
    public DataSource getDataSource() {
        System.out.println("Create datasource");
        BoneCPDataSource dataSource = new BoneCPDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        return dataSource;
    }

    @Bean
    public JdbcTemplate getJdbcTemplate() {
        System.out.println("Create jdbctemplate");
        DataSource datasource = getDataSource();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
        return jdbcTemplate;
    }
}
